﻿using Sample.Razor.Samples.DataList;

namespace Sample.Razor.Samples;

class DemoDataList : BaseComponent
{
    private readonly List<MenuItem> items = new()
    {
        new MenuItem("综合列表", "fa fa-list", typeof(FullList)),
        new MenuItem("综合表格", "fa fa-table", typeof(FullTable)),
        new MenuItem("普通表格", "fa fa-table", typeof(CommonTable)),
        new MenuItem("分页表格", "fa fa-table", typeof(PageTable)),
        new MenuItem("编辑表格", "fa fa-table", typeof(EditTable))
    };
    private MenuItem? curItem;

    protected override void OnInitialized()
    {
        curItem = items[0];
    }

    protected override void BuildRenderTree(RenderTreeBuilder builder)
    {
        builder.Div("box demo", attr =>
        {
            builder.Component<Tab>()
               .Set(c => c.CurItem, curItem?.Id)
               .Set(c => c.Items, items)
               .Set(c => c.OnChanged, OnTabChanged)
               .Build();
            builder.Div("tab-body top", attr => builder.DynamicComponent(curItem?.ComType));
        });
    }

    private void OnTabChanged(MenuItem item)
    {
        curItem = item;
        StateChanged();
    }
}